package com.gwq.computed;

import lombok.Data;

import java.util.Random;

@Data
public abstract class BinaryOperation2 {

    static final int UPPER = 100;
    static final int LOWER = 0;

    private int left_operand = 0,right_operand=0;
    private char operator = '+';
    private int value = 0;

    private void construct(int left,int  right,char op){
        left_operand = left;
        right_operand = right;
        operator = op;
        if(op=='+'){
            value = left+right;
        }else{
            value = left-right;
        }
    }

    //v2
    protected void generateBinaryOperation(char anOperator){
        int left,right,result;
        Random random = new Random();
        left = random.nextInt(UPPER+1);
        do{
            right = random.nextInt(UPPER+1);
            result = calculate(left,right);
        }while (!(checkingCalculation(result)));
        left_operand = left;
        right_operand = right;
        operator = anOperator;
        value = result;
    }

    abstract boolean checkingCalculation(int anInteger);
    abstract int calculate(int left,int right);



    public boolean equals(BinaryOperation2 binaryOperation){
        return left_operand == binaryOperation.getLeft_operand()&
                right_operand == binaryOperation.getRight_operand()&
                operator == binaryOperation.getOperator();
    }

    void unsafeConstructor(int left,int right,int value,char op){
        this.setLeft_operand(left);
        this.setRight_operand(right);
        this.setValue(value);
        this.setOperator(op);
    }


    public String toString(){
        return left_operand+""+operator+""+right_operand;
    }

    public String asString(){
        return left_operand+""+operator+""+right_operand+"=";
    }

    public String fullString(){
        return left_operand+""+operator+""+right_operand+"="+value;
    }


}

class AdditionOperation extends BinaryOperation2{

    AdditionOperation(){
        generateBinaryOperation('+');
    }

    @Override
    boolean checkingCalculation(int anInteger) {
        return anInteger<=UPPER;
    }

    @Override
    int calculate(int left, int right) {
        return left+right;
    }

//    void unsafeConstructor(int left,int right,int value,char op){
//        this.setLeft_operand(left);
//        this.setRight_operand(right);
//        this.setValue(value);
//        this.setOperator(op);
//    }
}


class SubstractOperation extends BinaryOperation2{
    SubstractOperation(){
        generateBinaryOperation('-');
    }
    @Override
    boolean checkingCalculation(int anInteger) {
        return anInteger>=LOWER;
    }

    @Override
    int calculate(int left, int right) {
        return left-right;
    }

//    void unsafeConstructor(int left,int right,int value,char op){
//        this.setLeft_operand(left);
//        this.setRight_operand(right);
//        this.setValue(value);
//        this.setOperator(op);
//    }
}




